//
//  UIBarButtonItem+Extensions.swift
//  PersonalWeibo
//
//  Created by Liuwx on 2017/9/18.
//  Copyright © 2017年 Liuwx. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    /// 创建 UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - font: fontSize, 默认16
    ///   - tagret:  taget
    ///   - action: action
    convenience init(title: String, font: CGFloat = 16, tagret: AnyObject?, action: Selector, isBack: Bool = false) {
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: font, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        btn.addTarget(tagret, action: action, for: .touchUpInside)
        if isBack {
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named: imageName), for: UIControlState(rawValue: 0))
            btn.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
            btn.sizeToFit()
        }
        //实例化UIBarButtonItem
        self.init(customView: btn)
        
        
    }
}
